﻿Public Class ConsultaObraSocialDAO
    Public Shared Function insertarConsultaObraSocial(ByVal ConsultaObraSocialMotivo As String, ByVal ConsultaObraSocialFecha As DateTime, ByVal ConsultaObraSocialFechaLimite As DateTime, ByVal TipoConsultaId As Integer, ByVal EmpleadoId As Integer, ByVal RepresentanteObraSocialId As Integer, ByVal ObraSocialId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            Constante.esNulo(ConsultaObraSocialMotivo)
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ConsultaObraSocial"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.INSERTAR).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialMotivo", ConsultaObraSocialMotivo).DbType = DbType.String
                    .AddWithValue("@ConsultaObraSocialFecha", ConsultaObraSocialFecha).DbType = DbType.DateTime
                    .AddWithValue("@ConsultaObraSocialFechaLimite", ConsultaObraSocialFechaLimite).DbType = DbType.DateTime
                    .AddWithValue("@TipoConsultaId", TipoConsultaId).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", EmpleadoId).DbType = DbType.Int32
                    .AddWithValue("@RepresentantenObraSocialId", RepresentanteObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", ObraSocialId).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerConsultasObraSocials(ByVal ConsultaObraSocialId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_ConsultaObraSocial_obtener", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@ConsultaObraSocialId", ConsultaObraSocialId).DbType = DbType.Int32
            da.Fill(ds, "ConsultasObraSocials")

            Return ds.Tables("ConsultasObraSocials")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function actualizarConsultaObraSocial(ByVal ConsultaObraSocialId As Integer, ByVal ConsultaObraSocialMotivo As String, ByVal ConsultaObraSocialFecha As DateTime, ByVal ConsultaObraSocialFechaLimite As DateTime, ByVal TipoConsultaId As Integer, ByVal EmpleadoId As Integer, ByVal RepresentanteObraSocialId As Integer, ByVal ObraSocialId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            Constante.esNulo(ConsultaObraSocialMotivo)
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ConsultaObraSocial"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialId", ConsultaObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialMotivo", ConsultaObraSocialMotivo).DbType = DbType.String
                    .AddWithValue("@ConsultaObraSocialFecha", ConsultaObraSocialFecha).DbType = DbType.DateTime
                    .AddWithValue("@ConsultaObraSocialFechaLimite", ConsultaObraSocialFechaLimite).DbType = DbType.DateTime
                    .AddWithValue("@TipoConsultaId", TipoConsultaId).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", EmpleadoId).DbType = DbType.Int32
                    .AddWithValue("@RepresentantenObraSocialId", RepresentanteObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", ObraSocialId).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()

            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function eliminarConsultaObraSocial(ByVal ConsultaObraSocialId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ConsultaObraSocial"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ELIMINAR).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialId", ConsultaObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@ConsultaObraSocialMotivo", Constante.VACIO).DbType = DbType.String
                    .AddWithValue("@ConsultaObraSocialFecha", Constante.FECHAVACIA).DbType = DbType.DateTime
                    .AddWithValue("@ConsultaObraSocialFechaLimite", Constante.FECHAVACIA).DbType = DbType.DateTime
                    .AddWithValue("@TipoConsultaId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@RepresentantenObraSocialId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", Constante.MENOSUNO).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With

            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function
End Class
